package com.idanchuang.component.base;

import com.idanchuang.component.base.actuator.DcInfoEndpoint;
import com.idanchuang.component.base.actuator.HealthInfoContributor;
import com.idanchuang.component.base.config.BaseConfigBean;
import com.idanchuang.component.base.exception.core.ExConfigure;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * @author yjy
 * @date 2020/7/6 10:49
 **/
@Configuration
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
public class ComponentBaseAutoConfiguration {

    @Bean
    @ConfigurationProperties("idanchuang.component.base")
    public BaseConfigBean baseConfigBean() {
        return new BaseConfigBean();
    }

    @Bean
    @ConfigurationProperties("error-code")
    @ConditionalOnMissingBean(ExConfigure.class)
    public ExConfigure errorCodeConfigure(BaseConfigBean baseConfigBean) {
        return new ExConfigure(baseConfigBean);
    }

    @Bean
    @ConditionalOnMissingBean(name = "acgInfoEndpoint")
    public DcInfoEndpoint acgInfoEndpoint(BaseConfigBean baseConfigBean) {
        return new DcInfoEndpoint(baseConfigBean);
    }

    @Bean
    @ConditionalOnMissingBean(name = "acgHealthInfoContributor")
    public HealthInfoContributor acgHealthInfoContributor(HealthEndpoint healthEndpoint) {
        return new HealthInfoContributor(healthEndpoint);
    }

}
